package net.cruciblesoftware.ghostspacekillah;

import android.graphics.Bitmap;
import android.graphics.Rect;
import java.util.LinkedList;

abstract class Ship extends FieldActor {
    public static final int STATE_DEAD = 0;
    public static final int STATE_EXPLODING = 1;
    public static final int STATE_LIVING = 2;
    public static final int STATE_MOVING = 3;

    protected float stateTime;

    protected Ship(int t) {
        super(t);
        setImage(Assets.getBitmap(type));
        setState(STATE_LIVING);
    }


    protected void setState(int newState) {
        state = newState;
        stateTime = 0.0f;
        switch(state) {
        case STATE_EXPLODING:
            setImage(Assets.getBitmap(FieldActor.TYPE_EXPLOSION));
            break;
        case STATE_LIVING:
        case STATE_MOVING:
            break;
        case STATE_DEAD:
            break;
        }
    }


    protected void updateAnimation(float elapsed) {
        frameTime += elapsed;
        if(frameTime > frameStepTime) {
            frameTime -= frameStepTime;
            currentFrame++;
            if(currentFrame >= nFrames)
                currentFrame = 0;
            src.left = currentFrame * imgWidth;
            src.right = (currentFrame+1) * imgWidth;
        }
    }


    @Override
    public void update(float elapsed) {
        if(state == Ship.STATE_EXPLODING) {
            stateTime += elapsed;
            if(stateTime > (nFrames * frameStepTime))
                setState(Ship.STATE_DEAD);
            return;
        }
    }

    /* Logging functions */
    private void logi(String msg) {
        android.util.Log.i(this.getClass().getName(), msg);
    }
    private void logw(String msg) {
        android.util.Log.w(this.getClass().getName(), msg);
    }
    private void loge(String msg) {
        android.util.Log.e(this.getClass().getName(), msg);
    }
}
